package cn.edu.fudan.dsm.MultiIndexes;

import cn.edu.fudan.dsm.MultiIndexes.operator.TimeSeriesOperator;
import cn.edu.fudan.dsm.MultiIndexes.operator.file.TimeSeriesFileOperator;

import java.io.*;
import java.util.List;

public class TransformData {
    public static void main(String[] args){
        try {
            long fileLength = 5000;
            long seriesLength = 500;

            File qfile = new File("files/data/1000_10_500_2f.dt");
            File dfile = new File("files/data/1000_500_2f.dt");
            FileOutputStream fos = new FileOutputStream(qfile);
            TimeSeriesOperator timeSeriesOperator = new TimeSeriesFileOperator("files/data/1000_10_500_2.qdt", fileLength, seriesLength, false);
            DataOutputStream dos = new DataOutputStream(fos);
            for(int i = 0; i < 10; i++){
                if(i > 999) continue;
                System.out.println(i);
                float ex = 0;
                float ex2 = 1;
                List<List<Double>> ts = timeSeriesOperator.readAllTimeSeries(i * seriesLength, seriesLength, seriesLength);
                for(int j = 0; j < seriesLength; j ++) if(Double.isInfinite(ts.get(0).get(j))) System.out.print(ts.get(0).get(j) + "\n");
                //System.out.println();
                /*for(int j = 0; j < ts.size(); j++){
                    ex += ts.get(j);
                    ex2 += ts.get(j) * ts.get(j);
                }
                ex /= seriesLength;
                ex2 = (float) Math.sqrt(ex2 / seriesLength - ex * ex);*/
                //System.out.println(ex + " " + ex2);
                /*for(int j = 0; j < ts.size() - 1; j++){
                    String s = ((float)ts.get(j).doubleValue() - ex) / ex2 + " ";
                    fos.write(s.getBytes());
                }
                fos.write((((float)ts.get(ts.size() - 1).doubleValue()- ex) / ex2 + "\n").getBytes());*/
                for(int j = 0; j < ts.get(0).size(); j ++) dos.writeFloat((float)((ts.get(0).get(j).doubleValue())));
            }
            dos.close();
            fos.close();
            /*FileInputStream fis = new FileInputStream(dfile);
            DataInputStream dis = new DataInputStream(fis);
            for(int j = 0; j < seriesLength; j ++) {
                System.out.print(dis.readFloat() + " ");
                System.out.print(j + " ");
            }
            System.out.println();
            dis.close();
            fis.close();*/
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}